<?php

namespace app\api\controller;


use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\Exception;

class Base extends Cross
{
    protected function initialize()
    {
        parent::initialize();
        //判断有没有token
        $header = request()->header();
        if (!isset($header['token'])){
            return json(['code'=>0,'msg'=>'请先登录'])->send();
        }
        if (empty($header['token'])){
            return json(['code'=>0,'msg'=>'请先登录'])->send();
        }
        //解析token
        $jwt = new JWT();
        $key ='api';
        $info = $jwt::decode($header['token'], new Key($key, 'HS256'));

        $this->aid = $info->uid;
//        return json(['code'=>1,'token'=>$info])->send();
    }
}